package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.itheima.roundedimageview.RoundedImageView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.ImageModle;
import hk.m4s.lr.repair.test.model.enValueModel;
import hk.m4s.lr.repair.test.views.InnerGridView;

/**
 * Created by qi.wang on 2017/3/16.
 */

public class EnGoodsAdapter extends BaseAdapter {
    public List<enValueModel.ListBean> list = new ArrayList<>();
    Context context;
    LayoutInflater inflater;
    private EnGridViewAdapter gvAdapter;
    private List<ImageModle> imgs;

    public EnGoodsAdapter(Context context, List<enValueModel.ListBean> data) {
        this.context = context;
        this.list = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item_en_goods, parent, false);
            holder.users_name = (TextView) convertView.findViewById(R.id.users_name);
            holder.goods_times = (TextView) convertView.findViewById(R.id.goods_times);
            holder.goods_style = (TextView) convertView.findViewById(R.id.goods_style);
            holder.goods_info = (TextView) convertView.findViewById(R.id.goods_info);
            holder.user_img = (RoundedImageView) convertView.findViewById(R.id.user_img);
            holder.picsGridView = (InnerGridView) convertView.findViewById(R.id.pics);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        enValueModel.ListBean newsModel = list.get(position);
        holder.users_name.setText(newsModel.getAnonymousname());
        holder.goods_times.setText(newsModel.getCommenttime());
        holder.goods_info.setText(newsModel.getContent());
        if (newsModel.getRemarktext() != null) {
            holder.goods_style.setText(newsModel.getRemarktext());
        }
        try {
            if (!(newsModel.getPics() == null || newsModel.getPics().equals(""))) {
                holder.picsGridView.setVisibility(View.VISIBLE);
                gvAdapter = new EnGridViewAdapter(context, newsModel.getPics());
                holder.picsGridView.setAdapter(gvAdapter);
            } else {
                holder.picsGridView.setVisibility(View.GONE);
            }
            if (newsModel.getCommentuserlogo() != null) {

                Glide.with(context).load(newsModel.getCommentuserlogo()).asBitmap().error(R.mipmap.default_head).into(holder.user_img);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    public static class ViewHolder {
        TextView users_name, goods_times, goods_style, goods_info;
        RoundedImageView user_img;
        InnerGridView picsGridView;
    }




}
